/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.hpvas.control;

import edu.hpvas.persistence.dao.OwnerDAO;
import edu.hpvas.persistence.dao.PetDAO;
import edu.hpvas.persistence.dao.VeterinarianDAO;
import edu.hpvas.persistence.entity.Owner;
import edu.hpvas.persistence.entity.Pet;
import edu.hpvas.persistence.entity.Veterinarian;
import java.util.ArrayList;

/**
 *
 * @author raider
 */
public class SearchController {

    public SearchController() {}
    
    public ArrayList<String[]> getSearchResults(String searchType,String words){
        ArrayList<String[]>searchResults=new ArrayList();
        switch(searchType){
            case "Veterinarian":
                searchResults.add(new String[]{
                    "Name",
                    "Last name",
                    "SSN",
                    "Birth date",
                    "Birth place",
                    "Focus of practice",
                    "Specialities",
                    "Salary",
                    "Graduated at"});
                for (String word:words.split(" ")) {
                    Veterinarian veterinarian = new VeterinarianDAO().findVeterinarianEntitiesByName(word);
                    if(veterinarian!=null){
                        searchResults.add(new String[]{
                        veterinarian.getIdPerson().getName(),
                        veterinarian.getIdPerson().getLastName(),
                        veterinarian.getIdPerson().getSsn(),
                        veterinarian.getIdPerson().getBirthdate().toString(),
                        veterinarian.getIdPerson().getBirthPlace(),
                        veterinarian.getFocusOfPractice(),
                        veterinarian.getSpecialities(),
                        veterinarian.getSalary().toString(),
                        veterinarian.getGraduateAt()});
                    }
                }
                break;
            case "Owner":
                searchResults.add(new String[]{
                    "Name",
                    "Last name",
                    "SSN",
                    "Birth date",
                    "Birth place"});
                Owner owner = new OwnerDAO().findOwnerEntitiesByNameOrSsn(words);
                if(owner!=null){
                    searchResults.add(new String[]{
                    owner.getIdPerson().getName(),
                    owner.getIdPerson().getLastName(),
                    owner.getIdPerson().getSsn(),
                    owner.getIdPerson().getBirthdate().toString(),
                    owner.getIdPerson().getBirthPlace()});
                }
                break;
            case "Pet":
                searchResults.add(new String[]{
                    "Name",
                    "Species",
                    "Age",
                    "Weight"});
                Pet pet = new PetDAO().findPetEntitiesByName(words);
                if(pet!=null){
                    searchResults.add(new String[]{
                    pet.getName(),
                    pet.getSpecies(),
                    pet.getAge().toString(),
                    pet.getWight().toString()});
                }
                break;
        }
        return searchResults;
    }
    
}
